<?php
/**
 * res controller
 * @package kernel_controller_resource
 */
load_lib('/app/controller');
/**
 * res controller
 * @author pandajingjing
 * @package kernel_controller_resource
 */
class resource_rescontroller extends app_controller{

	/**
	 * 入口方法
	 */
	function doRequest(){
		$strResourceURL=$this->getParam(0,'url');
		$strExt=substr($strResourceURL,strrpos($strResourceURL,'.'));
		$strSPre=get_config('s_resource_url_pre','resource');
		$strCBPre=get_config('cb_resource_url_pre','resource');
		if('.css'==$strExt){
			$this->addHeader('content-type:text/css; charset='.get_config('charset'));
			$strMethod='useCBStyle';
		}elseif('.js'==$strExt){
			$this->addHeader('content-type:application/x-javascript; charset='.get_config('charset'));
			$strMethod='useCBScript';
		}
		if(0===strpos($strResourceURL,$strSPre)){
			$this->setData('mixResource',substr($strResourceURL,strlen($strSPre)));
		}elseif(0===strpos($strResourceURL,$strCBPre)){
			if(get_config('combination','resource')){
				$arrCBStyle=array();
				$strPagePath=substr($strResourceURL,strlen($strCBPre),strpos($strResourceURL,$strExt)-strlen($strCBPre));
				load_page($strPagePath);
				$strPageName=path_to_pagename(substr($strResourceURL,strlen($strCBPre),strpos($strResourceURL,$strExt)-strlen($strCBPre)));
				$objRelClass=new ReflectionClass($strPageName);
				$objRelMethod=$objRelClass->getMethod('useComponent');
				$arrComponent=$objRelMethod->invoke(null);
				foreach($arrComponent as $strComponent){
					load_component($strComponent);
					$strComponentName=path_to_componentname($strComponent);
					$objRelClass=new ReflectionClass($strComponentName);
					$objRelMethod=$objRelClass->getMethod($strMethod);
					$arrComponentStyle=$objRelMethod->invoke(null);
					foreach($arrComponentStyle as $strComponentStyle){
						$arrCBStyle[]='/component'.$strComponentStyle;
					}
				}
				$objRelClass=new ReflectionClass($strPageName);
				$objRelMethod=$objRelClass->getMethod($strMethod);
				$arrTmpStyle=$objRelMethod->invoke(null);
				foreach($arrTmpStyle as $strTmpStyle){
					$arrCBStyle[]='/page'.$strTmpStyle;
				}
				$this->setData('mixResource',$arrCBStyle);
			}else{
				$this->setData('mixResource',substr($strResourceURL,strlen($strCBPre)));
			}
		}
		$this->addHeader('Cache-Control:max-age=3600');
		return '/resource/res';
	}
}